// programa teste Shell Unix para Trabalho SO 2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>

#define PROMPT "junekosh"

// Copied Function
void trim(char* name) {
  char* p = name ;
  size_t n ;	// igual a unsigned int

  // While not found " ",\t,\n,\v,\f,\r,
  while (isspace(*p))
    ++p ;
  if ((n = strlen(p)) > 0)
    while (isspace(p[n-1]))
      --n ;
  ((char*)memmove(name, p, n))[n] = '\0' ;
}


int main()
{
	char* input;
	char* buffer = (char*)calloc(1024,sizeof(char));
	while(1)
	{
		input = (char *)calloc(1024,sizeof(char));
		printf("%s - (%s)>",PROMPT,getcwd(buffer,1024));
		gets(input);
		trim(input);

   		 if ((strcmp(input, "") != 0) && (strcmp(input, ".") != 0) && (strcmp(input, "..") != 0)) 
		{
      			/* Verify exit COMMAND */
			if ((strcmp(input, "quit")== 0) || (strcmp(input, "exit")== 0)) {
			        printf("Good Bye~!\n");
			        return EXIT_SUCESS;
			}
        	}
	}
}
